package com.yxx.quartz.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.yxx.mapper.VisitLogMapper;
import com.yxx.service.RedisService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

import static com.yxx.constant.RedisConstant.UNIQUE_VISITOR;

/**
 * 执行定时任务
 * @author yuxiangxun
 * @date 2025/2/17
 * @apiNote
 */
@SuppressWarnings(value = "all")
@Component("timedTask")
public class TimedTask {
    @Resource
    private RedisService redisService;

    @Resource
    private VisitLogMapper visitLogMapper;

    /**
     * 清除博客访问记录
     */
    public void clear(){
        redisService.deleteObject(UNIQUE_VISITOR);
    }

    /**
     * 测试任务
     */
    public void test(){
        System.out.println("测试任务");
    }

    /**
     * 清除一周前的访问日志
     */
    public void clearVisitLog(){
        DateTime endTime = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -7));
        visitLogMapper.deleteVisitLog(endTime);
    }
}
